import java.util.Arrays;

public class leetcode167_两数之和_II_输入有序数组 {
    public static void main(String[] args) {
        Solution2 solution = new Solution2();
        int[] nums = new int[] {2,7,11,15};
        System.out.println(Arrays.toString(solution.twoSum(nums, 9)));
    }
}


class Solution2 {
    public int[] twoSum(int[] numbers, int target) {
        int i = 1, j = numbers.length;
        while (i < j) {
            int sum = numbers[i-1] + numbers[j-1];
            if (sum == target) {
                break;
            } else if (sum < target) {
                i++;
            } else {
                j--;
            }
        }
        return new int[] {i, j};
    }
}